package com.burstly.lib.component.networkcomponent.burstly.video;

import android.widget.VideoView;
import com.burstly.lib.network.request.RequestManager;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.util.Arrays;

public final class VideoTracker
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final int SLEEP_DELAY = 1000;
  private static final String TAG = "VideoTracker";
  volatile boolean mCancelled;
  final String[] mMiddleTrackUrl;
  volatile boolean mPaused;
  final VideoView mPlayer;
  private Runnable mTracker;

  VideoTracker(VideoView paramVideoView, String[] paramArrayOfString)
  {
    this.mPlayer = paramVideoView;
    this.mMiddleTrackUrl = paramArrayOfString;
    if ((paramArrayOfString != null) && (paramArrayOfString.length > 0))
    {
      this.mTracker = createTrackerRunnable();
      return;
    }
    LOG.logWarning("VideoTracker", "Track video middle request will not be sent because of the url is null.", new Object[0]);
  }

  private Runnable createTrackerRunnable()
  {
    return new Runnable()
    {
      private int getVideoDuration()
      {
        int i = -1;
        for (int j = 0; ; j++)
          if (j < 3)
          {
            VideoTracker.sleep(300);
            i = VideoTracker.this.mPlayer.getDuration();
            if (i <= 0);
          }
          else
          {
            return i;
          }
      }

      private void sendRequest(String[] paramAnonymousArrayOfString, String paramAnonymousString)
      {
        int i = paramAnonymousArrayOfString.length;
        for (int j = 0; j < i; j++)
          RequestManager.makeTrackEventRequest(paramAnonymousArrayOfString[j], paramAnonymousString);
      }

      public void run()
      {
        while (true)
        {
          try
          {
            Utils.lowerCurrentThreadPriority();
            int i = 0;
            int j = getVideoDuration();
            LoggerExt localLoggerExt = VideoTracker.LOG;
            Object[] arrayOfObject = new Object[1];
            arrayOfObject[0] = Integer.valueOf(j);
            localLoggerExt.logInfo("VideoTracker", "Video duration: {0}", arrayOfObject);
            int k = j / 2;
            if (!VideoTracker.this.mCancelled)
            {
              if ((VideoTracker.this.mPaused) || (i >= j))
                continue;
              i = VideoTracker.this.mPlayer.getCurrentPosition();
              if ((i < k) || (i >= j))
                break label142;
              VideoTracker.LOG.logInfo("VideoTracker", "Sending track video middle request...", new Object[0]);
              sendRequest(VideoTracker.this.mMiddleTrackUrl, "VideoTracker TrackMiddle");
              VideoTracker.this.cancel();
              continue;
            }
          }
          catch (Exception localException)
          {
            VideoTracker.LOG.logThrowable("VideoTracker", localException);
          }
          return;
          label142: VideoTracker.sleep(1000);
        }
      }
    };
  }

  private static void sendRequest(String paramString1, String paramString2, String paramString3)
  {
    if (paramString1 != null)
    {
      RequestManager.makeTrackEventRequest(paramString1, paramString2);
      return;
    }
    LOG.logWarning("VideoTracker", paramString3, new Object[0]);
  }

  private void setPaused(boolean paramBoolean)
  {
    LoggerExt localLoggerExt;
    if (this.mTracker != null)
    {
      localLoggerExt = LOG;
      if (!paramBoolean)
        break label36;
    }
    label36: for (String str = "Pause video watch thread."; ; str = "Unpause video watch thread.")
    {
      localLoggerExt.logDebug("VideoTracker", str, new Object[0]);
      this.mPaused = paramBoolean;
      return;
    }
  }

  static void sleep(int paramInt)
  {
    long l = paramInt;
    try
    {
      Thread.sleep(l);
      return;
    }
    catch (InterruptedException localInterruptedException)
    {
    }
  }

  static void trackVideoEnd(String[] paramArrayOfString)
  {
    int i = paramArrayOfString.length;
    for (int j = 0; j < i; j++)
      sendRequest(paramArrayOfString[j], "VideoTracker TrackEnd", "Can not send watch-to-the-end track request because of urls are null");
  }

  void cancel()
  {
    if (!this.mCancelled)
    {
      setPaused(true);
      if (this.mTracker != null)
      {
        LOG.logDebug("VideoTracker", "Cancel video watch thread.", new Object[0]);
        this.mTracker = null;
      }
      this.mCancelled = true;
    }
  }

  void pause()
  {
    setPaused(true);
  }

  void resume()
  {
    setPaused(false);
  }

  void startMiddlepointTracking()
  {
    if (this.mTracker != null)
    {
      LOG.logDebug("VideoTracker", "Started middle point tracker...", new Object[0]);
      Thread localThread = new Thread(this.mTracker);
      localThread.setName(Arrays.toString(this.mMiddleTrackUrl) + " tracker");
      localThread.start();
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.video.VideoTracker
 * JD-Core Version:    0.6.2
 */